import { type UserInfoInter } from '@/types/userInfo'
import { useUserInfoStore } from '@/stores/userInfo'
import router from '@/router/index'

export function setUserInfo(userInfo: UserInfoInter) {
  localStorage.setItem('userInfo', JSON.stringify(userInfo))
}
export function getUserInfo() {
  return localStorage.getItem('userInfo')
}

export function setToken(token: string) {
  localStorage.setItem('token', token)
}

export function removeUserInfo() {
  localStorage.removeItem('userInfo')
}

export function getToken() {
  return localStorage.getItem('token')
}

export function removeToken() {
  localStorage.removeItem('token')
}

export function loginOut() {
  removeToken()
  removeUserInfo()
  useUserInfoStore().logout()
  setTimeout(() => {
    router.push('/login')
    // location.href = '#/login'
  }, 1000)
}
